package service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pojo.Photo;
import utils.FileUtils;
import dao.ImageDAO;

@Service
public class ImageService {

  @Autowired
  private ImageDAO dao;
  
  public void addImage(Photo photo){
    this.dao.addImage(photo);
  }
  
  public List<Photo> selectImage(int userID){
    return this.dao.selectByUserID(userID);
  }
  
  public void delete(String urls,String IDs){
    String[] s = urls.split(",");
    String[] idarr = IDs.split(",");
    for(String url:s){
      FileUtils.delete(url);
    }
    for(String id:idarr){
      int i = Integer.parseInt(id);
      this.dao.delete(i);
    }
  }
}
